package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.app.entity.TOrganizationEntity;
import io.renren.modules.app.service.TOrganizationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 组织表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-04-26 17:08:24
 */
@RestController
@RequestMapping("app/torganization")
public class TOrganizationController {
    @Autowired
    private TOrganizationService tOrganizationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("app:torganization:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tOrganizationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("app:torganization:info")
    public R info(@PathVariable("id") Integer id){
        TOrganizationEntity tOrganization = tOrganizationService.getById(id);

        return R.ok().put("tOrganization", tOrganization);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("app:torganization:save")
    public R save(@RequestBody TOrganizationEntity tOrganization){
        tOrganizationService.save(tOrganization);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("app:torganization:update")
    public R update(@RequestBody TOrganizationEntity tOrganization){
        ValidatorUtils.validateEntity(tOrganization);
        tOrganizationService.updateById(tOrganization);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("app:torganization:delete")
    public R delete(@RequestBody Integer[] ids){
        tOrganizationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
